CC= g++
CTPDIR= lib/v6.3.15_20190220_api_tradeapi_se_linux64/
CFLAGS= -std=c++11 -fPIC -g -Icommon/ -Ilib/ -I$(CTPDIR)
OBJ= obj/
BIN= bin/
all:init service strategy tools
init:
	mkdir -p $(BIN)
	mkdir -p $(OBJ)
service:auto_trade_td auto_trade_md
strategy:momentum monitor
tools: client read-order

$(OBJ)%.o: common/%.cpp
	$(CC) $(CFLAGS) -c -o $@ $< 

$(OBJ)%.o: st/%.cpp
	$(CC) $(CFLAGS) -c -o $@ $< 

$(OBJ)%.o: md/%.cpp
	$(CC) $(CFLAGS) -c -o $@ $< 

$(OBJ)%.o: td/%.cpp
	$(CC) $(CFLAGS) -c -o $@ $< 


$(OBJ)%.o: tools/%.cpp
	$(CC) $(CFLAGS) -c -o $@ $< 


auto_trade_md:$(patsubst %,$(OBJ)%,Spi.o subscriber.o)
	$(CC) -o $(BIN)$@ $^ $(patsubst %,$(CTPDIR)%,thostmduserapi_se.so thosttraderapi_se.so)

auto_trade_td:$(patsubst %,$(OBJ)%, TdSpi.o trader.o)
	$(CC) -o $(BIN)$@ $^ $(patsubst %,$(CTPDIR)%,thosttraderapi_se.so)

momentum:$(patsubst %,$(OBJ)%,Strategy.o momentum.o)
	$(CC) -o $(BIN)$@ $^

monitor:$(patsubst %,$(OBJ)%, Strategy.o monitor.o)
	$(CC) -o $(BIN)$@ $^

client:$(patsubst %,$(OBJ)%, Tester.o client.o)
	$(CC) -o $(BIN)$@ $^ $(patsubst %,$(CTPDIR)%,thosttraderapi_se.so)

read-order:$(patsubst %,$(OBJ)%, read-order.o)
	$(CC) -o $(BIN)$@ $^

clean:
	rm -rf $(OBJ)
	rm -rf $(BIN)
